Helper.using('py.Figures', function (ns) {

    ns.Segment = function (params) {
        ns.LinearObject.call(this, params);

        this.visual(new Kinetic.Line({
            stroke:"black",
            strokeWidth:2,
            lineCap:"round",
            lineJoin:"round"
        }));

        // @returns array
        this.getEnds = Helper.abstractMethod();

        this.getLength = function () {
            return ns.Point.distance.apply(null, this.getEnds());
        }

        this.update = function (viewPort) {
            var ends = this.getEnds(),
                p1 = viewPort.getPixelPoint(ends[0].getPosition()),
                p2 = viewPort.getPixelPoint(ends[1].getPosition()),
                points = [p1.x, p1.y , p2.x, p2.y],
                visual = this.visual();
            visual.setPoints(points);
        }

        this.drawFunc = function (viewPort) {
            this.update(viewPort);
            this.layer().draw();
        }

        //@override linear object
        this.getAnchor = function () {
            return this.getEnds()[0];
        };

        this.getDirectionVector = function() {
            var ends = this.getEnds();
            return new ns.Vector2Point({head: ends[0], tail: ends[1] });
        };

        this.getMagnitude = function() {
            return this.getLength();
        }
    };

    ns.Segment2Point = function (params) {
        params = Helper.extend({
            ends:[]
        }, params);

        ns.Segment.call(this, params);


        this.getEnds = function () {
            return params.ends;
        };

        this.setEnds = function (ends) {
            params.ends = ends;
        };

        this.setPoint = function (index, point) {
            if (index != 0 && index != 1) {
                return false;
            }
            params.ends[index] = point;
        };

        this.toString = function () {
            return 'Segment: {length:' + this.getLength() + '}';
        }
    }


    ns.Segment.prototype.toString = function () {
        return 'Segment: {length:' + this.getLength() + '}';
    }
});